﻿using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
using WpfTwitterClient.Infrastructure;
using WpfTwitterClient.Modules.Status.Views.Status;

namespace WpfTwitterClient.Modules.Status
{
    public class StatusModule : IModule
    {
        private readonly IUnityContainer container;
        private readonly IRegionManager regionManager;
        private IEventAggregator eventAggregator;

        public StatusModule(IUnityContainer container, IRegionManager regionManager, IEventAggregator eventAggregator)
        {
            this.regionManager = regionManager;
            this.container = container;
            this.eventAggregator = eventAggregator;
        }

        public void Initialize()
        {
            RegisterViewsAndServices();

            var presenter = this.container.Resolve<IStatusPresenter>();

            IRegion region = this.regionManager.Regions[RegionNames.StatusRegion];
            region.Add(presenter.View, "StatusView");
            region.Activate(presenter.View);
        }


        protected void RegisterViewsAndServices()
        {
            // TODO: Should be singleton
            this.container.RegisterType<IStatusView, StatusView>();
            this.container.RegisterType<IStatusPresenter, StatusPresenter>();
            this.container.RegisterType<IStatusPresentationModel, StatusPresentationModel>();
        }

    }
}
